package com.xquant.marketdata.marketdata.controller;

import com.xquant.marketdata.marketdata.domain.StockBonusDTO;
import com.xquant.marketdata.marketdata.domain.StockInfoDTO;
import com.xquant.marketdata.marketdata.domain.StockPriceDTO;
import com.xquant.marketdata.marketdata.service.StockService;
import com.xquant.common.security.utils.ExcelUtil;
import com.xquant.common.core.web.controller.BaseController;
import com.xquant.common.core.web.page.TableDataInfo;
import com.xquant.common.log.annotation.Log;
import com.xquant.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 股票
 * <p>
 * newCloud
 *
 * @author ershuai.zhao
 */
@RestController
@RequestMapping("/stockController")
public class StockController extends BaseController {

    @Autowired
    private StockService stockService;

    /**
     * 查询 股票信息
     */
    @PreAuthorize("@ss.hasPermi('marketdata:equity:shares:sharesInfo:list')")
    @RequestMapping(value = "/queryStockInfoByPage.action")
    public TableDataInfo queryStockInfoByPage(@RequestParam Map<String, Object> param) {
        startPage();
        return getDataTable(stockService.queryStockInfoByPage(param));
    }


    @Log(title = "股票信息", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('marketdata:equity:shares:sharesInfo:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam Map<String, Object> param) {
        startPage();
        List<StockInfoDTO> list = stockService.queryStockInfoByPage(param);
        ExcelUtil<StockInfoDTO> util = new ExcelUtil<StockInfoDTO>(StockInfoDTO.class);
        util.exportExcel(response, list, "股票信息");
    }


    @Log(title = "股票行情", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('marketdata:equity:shares:sharesInfo:export')")
    @PostMapping("/exportPrice")
    public void exportPrice(HttpServletResponse response, @RequestParam Map<String, Object> param) {
        startPage();
        List<StockPriceDTO> list = stockService.queryStockPriceByPage(param);
        ExcelUtil<StockPriceDTO> util = new ExcelUtil<StockPriceDTO>(StockPriceDTO.class);
        util.exportExcel(response, list, "股票行情");
    }


    @Log(title = "股票分红信息", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('marketdata:equity:shares:sharesBonus:export')")
    @PostMapping("/exportBonus")
    public void exportBonus(HttpServletResponse response, @RequestParam Map<String, Object> param) {
        startPage();
        List<StockBonusDTO> list = stockService.queryStockDividendByPage(param);
        ExcelUtil<StockBonusDTO> util = new ExcelUtil<StockBonusDTO>(StockBonusDTO.class);
        util.exportExcel(response, list, "股票分红信息");
    }

    /**
     * 查询 股票分红
     */
    @PreAuthorize("@ss.hasPermi('marketdata:equity:shares:sharesBonus:list')")
    @RequestMapping(value = "/queryStockDividendByPage.action")
    public TableDataInfo queryStockDividendByPage(@RequestParam Map<String, Object> param) {
        startPage();
        return getDataTable(stockService.queryStockDividendByPage(param));
    }

    /**
     * 查询 股票行情
     */
    @PreAuthorize("@ss.hasPermi('marketdata:equity:shares:sharesQuota:list')")
    @RequestMapping(value = "/queryStockPriceByPage.action")
    public TableDataInfo queryStockPriceByPage(@RequestParam Map<String, Object> param) {
        startPage();
        return getDataTable(stockService.queryStockPriceByPage(param));
    }


}
